package com.example.identifyvisio.service;



import com.example.identifyvisio.model.component.CoordinatesAndParent;
import com.example.identifyvisio.model.component.Position;
import com.example.identifyvisio.model.node.Ports;
import com.example.identifyvisio.model.component.Size;
import com.example.identifyvisio.model.node.judge.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import static com.example.identifyvisio.utis.NodeValueUtil.getObtainCoordinates;
import static com.example.identifyvisio.utis.NodeValueUtil.getPorts;


public class JudgeService {

    /**
     * 判断节点
     *
     * @param
     * @param
     * @return
     */
    public static Judge getJudge(HashMap<Integer, Map<String, String>> dataMap, Integer shapeID,
                                 Map<String, String> shapeMap, HashMap<String, List<Position>> positionMap) {
        Judge judge = new Judge();

        //获取坐标和父节点
        CoordinatesAndParent obtainCoordinates = getObtainCoordinates(dataMap, shapeMap, positionMap);

        judge.setPosition(obtainCoordinates.getPosition());
        judge.setParent(obtainCoordinates.getParent());

        Size obtainSize = obtainCoordinates.getSize();
        Size size = new Size("判定");
        if (obtainSize.getWidth() != 0.0){
            size.setWidth(obtainSize.getWidth());
        }
        if (obtainSize.getHeight() != 0.0){
            size.setHeight(obtainSize.getHeight());
        }
        judge.setSize(size);
        Body body = new Body("0,10 10,0 20,10 10,20", "#95b7ff","#95b7ff");
        //获取文本
        String text = shapeMap.get("text");
        TextWrap textWrap = new TextWrap(text, true, -10, true);
        Text label = new Text(8, "#fff", textWrap);
        Attrs attrs = new Attrs(body, label);
        judge.setAttrs(attrs);
        judge.setShape("custom-polygon");

        Ports ports = getPorts();
        judge.setPorts(ports);

        String uniqueID = shapeMap.get("UniqueID");
        judge.setId(uniqueID);

        JudgeData judgeData = new JudgeData();
        judgeData.setLabel(text);
        judgeData.setStateId(dataMap.get(shapeID).get("stateId"));
        judgeData.setStateType("Choice");

        judge.setData(judgeData);

        judge.setZIndex("10");

        return judge;
    }

}
